package com.agile.leetcode.httpclient;

import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;
import java.time.LocalTime;

/**
 * apache发送json post请求
 * @Author:ChenZhangKun
 * @Date: 2023/4/3 21:57
 */
public class PostDemo2 {
    public static void main(String[] args) throws IOException {
        CloseableHttpClient aDefault = HttpClients.createDefault();
        HttpPost httpPost=new HttpPost("");
        httpPost.addHeader("Content-Type", "application/json");//设置httpPost的请求头中的MIME类型为json

        // 设置json类型的格式参数
        StringEntity stringEntity=new StringEntity("","utf-8");

        httpPost.setEntity(stringEntity);
        LocalTime now = LocalTime.now();
        CloseableHttpResponse response = aDefault.execute(httpPost);

        StatusLine statusLine = response.getStatusLine();


        int statusCode = statusLine.getStatusCode();

        if (statusCode==200){
            System.out.println(response);
        }
    }

}
